package org.speed.data;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NIOServelet extends HttpServlet  {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		
		AsyncContext asyncContext = req.getAsyncContext();
		
		asyncContext.getRequest().getInputStream().setReadListener(new ReadListener() {
			
			@Override
			public void onError(Throwable throwable) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onDataAvailable() throws IOException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAllDataRead() throws IOException {
				// TODO Auto-generated method stub
				
			}
		});
		asyncContext.addListener(new AsyncListener() {
			
			@Override
			public void onTimeout(AsyncEvent event) throws IOException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onStartAsync(AsyncEvent event) throws IOException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onError(AsyncEvent event) throws IOException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onComplete(AsyncEvent event) throws IOException {
				// TODO Auto-generated method stub
				
			}
		});
		
		
		asyncContext.getResponse().getOutputStream().setWriteListener(new WriteListener() {
			
			@Override
			public void onWritePossible() throws IOException {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onError(Throwable throwable) {
				// TODO Auto-generated method stub
				
			}
		});
		
		
		asyncContext.start(new Runnable() {
			
			@Override
			public void run() {
				asyncContext.complete();
			}
		});
		
		
	}

}
